﻿//********************************************************************************//
//创建日期：<创建日期，2017-06-13>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：处理报表相关
//********************************************************************************//

using System;
using System.Web;
using Newtonsoft.Json;
using Entity;
using BLL;
using System.Web.SessionState;

namespace Web.ashx
{

    /// <summary>
    /// Common 的摘要说明
    /// </summary>
    public class BaoBiao : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request["op"] == "List")//获取报表
            {

                //var s = new DALBaoBiaoDY().GetAll(BusinessTool.WType, 1);
                var s = new DALBaoBiaoDY().GetAllByuser(BusinessTool.WType, 1,LoginInfo.CurrentUser.UserID);
                context.Response.Write(JsonConvert.SerializeObject(s));
            }
            else if (context.Request["op"] == "CSList")//获取报表参数列表
            {
                var wtype = Convert.ToInt32(context.Session["WType"]);
                int bbid= int.Parse(context.Request["bbid"]);
                string SLYM = BusinessTool.GetSLYMorZWNY(1, wtype).ToString();
                string slyear = SLYM.Substring(0, 4);
                string slmonth = SLYM.Substring(4, 2);
                string ZWYM = BusinessTool.GetSLYMorZWNY(2, wtype).ToString();
                string zwyear = ZWYM.Substring(0, 4);
                string zwmonth = ZWYM.Substring(4, 2);
                var results = new DALBaoBiaoCS().GetByBaoBiaoId(bbid);
                foreach (var result in results)
                {
                    if (result.S_CANSHUMC.Contains("年"))
                    {
                        result.S_CANSHUZ = slyear;
                    }
                    if (result.S_CANSHUMC.Contains("月"))
                    {
                        result.S_CANSHUZ = slmonth;
                    }
                    if (result.S_CANSHUMC.Contains("帐务年"))
                    {
                        result.S_CANSHUZ = zwyear;
                    }
                    if (result.S_CANSHUMC.Contains("帐务月"))
                    {
                        result.S_CANSHUZ = zwmonth;
                    }
                    if (result.S_CANSHUMC.Contains("开帐年"))
                    {
                        result.S_CANSHUZ = zwyear;
                    }
                    if (result.S_CANSHUMC.Contains("开帐月"))
                    {
                        result.S_CANSHUZ = zwmonth;
                    }
                    if (result.S_CANSHUMC.Contains("账务年"))
                    {
                        result.S_CANSHUZ = zwyear;
                    }
                    if (result.S_CANSHUMC.Contains("账务月"))
                    {
                        result.S_CANSHUZ = zwmonth;
                    }
                    if (result.S_CANSHUMC.Contains("开账年"))
                    {
                        result.S_CANSHUZ = zwyear;
                    }
                    if (result.S_CANSHUMC.Contains("开账月"))
                    {
                        result.S_CANSHUZ = zwmonth;
                    }
                    if (result.S_CANSHUMC.Contains("水量年"))
                    {
                        result.S_CANSHUZ = slyear;
                    }
                    if (result.S_CANSHUMC.Contains("水量月"))
                    {
                        result.S_CANSHUZ = slmonth;
                    }
                    if (result.S_CANSHUMC.Contains("年月"))
                    {
                        result.S_CANSHUZ = SLYM;
                    }
                    if (result.S_CANSHUMC.Contains("水量年月"))
                    {
                        result.S_CANSHUZ = SLYM;
                    }
                    if (result.S_CANSHUMC.Contains("账务年月"))
                    {
                        result.S_CANSHUZ = ZWYM;
                    }
                    if (result.S_CANSHUMC.Contains("开账年月"))
                    {
                        result.S_CANSHUZ = ZWYM;
                    }

                }
                context.Response.Write(JsonConvert.SerializeObject(results));
            }
            else if (context.Request["op"] == "CSZList")//获取筛选类型参数值列表
            {
                int bbid = int.Parse(context.Request["bbid"]);
                string sjy = context.Request["cssjy"];
                int sjyvale = string.IsNullOrEmpty(sjy) ? 0 : int.Parse(sjy);
                context.Response.Write(JsonConvert.SerializeObject(new DALBaoBiaoCS().GetDDLList(bbid,sjyvale)));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}